<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body></body>
  <script>
    //     输入：s = "babad"
    // 输出："bab"
    // 解释："aba" 同样是符合题意的答案。
    //1.以每一个字符为中心 向左 向右 去比较 
    console.log(gestPalindrome('aba'),"=====213");
    function gestPalindrome(s) {
      let maxStr = "";
      let len = s.length;
      for (let i = 0; i < len ; i++) {
        deff(i, i);
        //它还需要检查一下 相邻的两个会不会 相等
        deff(i, i + 1);
      }
      function deff(l, r) {
        while (l >= 0 && r < len && s[l] == s[r]) {
          l--;
          r++;
        }
        let max = s.slice(r + 1, r);
        if (max.length > maxStr.length) maxStr = max;
      }
      return maxStr;
    }
  </script>
</html>
